package com.jay.io.intf;

import java.io.File;
import java.io.FilenameFilter;

public class FilenameFilterIntf implements FilenameFilter {
	public boolean isGif(String file) {
		if (file.toLowerCase().endsWith(".gif")) {
			return true;
		} else {
			return false;
		}
	}

	public boolean isJpg(String file) {
		if (file.toLowerCase().endsWith(".jpg")) {
			return true;
		} else {
			return false;
		}
	}

	public boolean isPng(String file) {
		if (file.toLowerCase().endsWith(".png")) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public boolean accept(File dir, String fname) {
		return (isGif(fname) || isJpg(fname) || isPng(fname));
	}

	public static void main(String[] args) {
		File directory = new File(
				"C:/Documents and Settings/jay.li/My Documents/My Pictures");
		String[] images = directory.list(new FilenameFilterIntf());
		System.out.println("size=" + images.length);
		for (int i = 0; i < images.length; i++) {
			String imgfile = images[i];
			System.out.println("imgfile=" + imgfile);
		}
	}
}
